<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>实例</title>
    <script type="text/javascript" src="../assets/js/vue-2.3.0.js"></script>
    <script type="text/javascript" src="../assets/js/jquery.js"></script>
</head>
<body>
    <h1>实例方法-生命周期</h1>
    <hr>
    <div id="app">
        {{message}}
    </div>
    <div id="wu-kong"></div>
    <p><button onclick="destroy()">销毁</button></p>
    <p><button onclick="reload()">刷新</button></p>
    <p><button onclick="tick()">更新数据</button></p>
</body>
<script type="text/javascript">
    var componentA = Vue.extend({
        template:'<div>{{name}}-{{from}}</div>',
        data:function(){
            return {
                name:'悟空',
                from:'花果山'
            }
        },
        destroyed:function(){
            console.log('销毁了');
        },
        updated:function () { 
           console.log('被更新了');
        }
    })
    var vm = new componentA().$mount('#wu-kong')
    var app = new Vue({
        el:'#app',
        data:{
            message: 'helloworld!'
        },
        methods:{
            add:function(){
                console.log('调用成功')
            }
        }
    })
    function destroy(){
        vm.$destroy();
    }
    function reload(){
        vm.$forceUpdate();
    }
    function tick(){
        vm.name="猴哥";
        vm.$nextTick(function(){
            console.log('name更新完后我被调用了');
        })
    }
</script>
</html>